package com.hc.pingtan.controller;

import com.hc.pingtan.conf.SsoUrlConfig;
import com.hc.pingtan.model.CommonResult;
import com.hc.pingtan.service.SsoAccountCreate;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "用户跳转")
@RestController
@RequestMapping("/sso")
public class SsoUserController {
    @Resource
    private SsoUrlConfig config;
    @Resource
    private List<SsoAccountCreate> ssoAccountCreateList;

    @RequestMapping("login")

    public CommonResult<String> login(@RequestParam("platform") String platform, @RequestParam("type") String type,
                                      @RequestParam("account") String account) {
        for (SsoAccountCreate ssoAccountCreate : ssoAccountCreateList) {
            ssoAccountCreate.createAccount(account);
        }
        String url = config.getUrl().get(platform).get(type);
        url = url.replace("#{account}", account).replace("#{password}", "123456");
        return CommonResult.<String>builder().result(url).build();
    }
}
